define(["jquery","cookie"],function($){
	function Header(){
		this.load();
	}
	Header.prototype={
		constructor:Header,
		load:function(){
			$.get("/html/include/header.html",$.proxy(this.headerHandle,this));
			$("footer").load("/html/include/footer.html")
		},
		headerHandle:function(data){
			$("header").html(data);
			this.loadLoginUser();
			this.loadCartAmount();
		},
		loadLoginUser:function(){
			$.cookie.json = true;
			var user = $.cookie("login-user");
			if(user){
				$("#login").parent("#lo-re").html(`<span id="span-txt">欢迎您，</span><a href="javascript:;" id="self">${user.userphone}</a><a href="#" id="logout">退出</a>`);
				this.addListener();
			}
		},
		loadCartAmount:function(){
			$.cookie.json = true;
			var cart = $.cookie("cart");
			if(cart){
				$("#cart-num").text(cart.length);
			}
		},
		addListener:function(){
			$("#logout").click($.proxy(this.logoutHandel,this));
		},
		logoutHandel:function(){
			$.cookie("login-user","",{expires:-1,path:"/"});
			$("#login").parent("#lo-re").html(`<a href="/html/login.html" id="login">登录</a>
				<span>|</span>
				<a href="/html/register.html" id="register">注册</a>`);
			window.location.reload();
		}
	}
	new Header();
});